﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using GWEB.WebBase.Entity;
using GWEB.WebBase.Utility;
using GWEB.WebFrame.Public;

namespace GWEB.WebFrame.Models
{
    public class AtSp
    {
        public PageInfo Init()
        {
            PageInfo pg = new PageInfo();
            pg.Type = "AtSp";
            pg.Title = "财务中心";
            pg.AddText = "新增";
            pg.EditText = "";
            pg.LocateText = "查询";
            pg.SMenuId = "CW02";
            pg.FileUrl = "../Account/At";
            pg.Condition =  "";
            pg.TableName = "cu_Account";
         
            pg.KeyFieldName = "id";
            pg.PopEditHeight = 550;
            pg.PopEditWidth = 760;
            HttpSessionState session = System.Web.HttpContext.Current.Session;
            pg.dict = BasePage.getDict(session);
            pg.Sop = BasePage.Grant(session, pg.SMenuId);
            pg.Sop.ADD = false; pg.Sop.DEL = false;
            pg.Sop.EDIT_htm = " ";
            string Url = "../Account/At/UpdateState";//convert(varchar(10), cu_Account.id)
       
            pg.Sql = @"select cu_Account.*,Fb.dname FlowingTypeName,Ab.dname AccountModeName,
             case cu_Account.AccountType when '收入类' then case cu_Account.state  when 2 then '<a class=''layui-btn layui-btn-primary layui-btn-xs'' href=""javascript: Print()"" >小票</a><a class=''layui-btn layui-bg-red layui-btn-xs'' href=""javascript: Do(''" + Url + @"'',{ id: '+ltrim(cu_Account.id)+',keyCode: GetKeyCode('''+ltrim(cu_Account.id)+'''),state:4})"" >作废</a>'  end else  case cu_Account.state when 1 then '<a class=''layui-btn  layui-btn-xs'' href=""javascript: Do(''" + Url + @"'',{ id: '+ltrim(cu_Account.id)+',keyCode: GetKeyCode('''+ltrim(cu_Account.id)+'''),state:2})"" >通过</a><a class=''layui-btn layui-bg-red layui-btn-xs'' href=""javascript: Do(''" + Url + @"'',{ id: '+ltrim(cu_Account.id)+',keyCode: GetKeyCode('''+ltrim(cu_Account.id)+'''),state:0})"" >退回</a>'  when 2 then  '<a class=''layui-btn layui-btn-primary layui-btn-xs'' href=""javascript: Print()"" >小票</a><a class=''layui-btn layui-bg-red layui-btn-xs'' href=""javascript: Do(''" + Url + @"'',{ id: '+ltrim(cu_Account.id)+',keyCode: GetKeyCode('''+ltrim(cu_Account.id)+'''),state:4})"" >作废</a>'  end   end as link,
             case SUBSTRING(cu_Account.FlowingType, 4, 2)  when  '01' then '订金收入:' + cu_Customers.LinkName + '联系电话:' + cu_Customers.CustTel + '宝宝姓名：' + cu_Customers.custname when  '02' then '合同收入:' +cu_Contract.contractNumber + '应收:' + convert(varchar(10),ContractPrice) + '实收：' + convert(varchar(10),DisPrice) when  '03' then '活动信息:' + cu_Activity.ActivityName + '联系电话:' + cu_Activity.Tel + '会价格：' + convert(varchar(12), cu_Activity.MPrice) + '非会员价:' + convert(varchar(12), cu_Activity.NoMPrice) else '' end CustMessage,
             case cu_Account.AccountType when '收入类' then case cu_Account.state when 0 then '<span class=''layui-badge layui-bg-orange''>未入帐</span>' when 2 then '已入帐' when 3 then  '<span class=''layui-badge layui-bg-gray''>已使用</span>' when 4 then '<span style=''text-decoration:line-through''>已作废</span>' else '未审核' end else case cu_Account.state when 0 then '未审核' when 2 then '已审核'  when 3 then '<span class=''layui-badge layui-bg-gray''>已使用</span>' when 4 then '<span style=''text-decoration:line-through;color:red''>已作废</span>' else '已提交未审核' end end stateName,
            AudiUser.sshowname+'/'+convert(varchar(10),cu_Account.AuditingDate,120) AuditMessage,
            CreateUser.sshowname+'/'+convert(varchar(10),cu_Account.CreateDate,120) createMessage
            from cu_Account
            left join tb_sys_dictionary Fb on Fb.did = cu_Account.FlowingType
            left
            join tb_sys_dictionary Ab on Ab.did = cu_Account.AccountMode
            left
            join cu_Customers on cu_Customers.id = cu_Account.cid
            left
            join cu_Contract on cu_Contract.id = cu_Account.ContractId
            left
            join cu_Activity on cu_Activity.id = cu_Account.activityId
            left
            join tb_sys_users CreateUser on CreateUser.iuserid  = cu_Account.createId
            left
            join tb_sys_users AudiUser on AudiUser.iuserid  = cu_Account.AuditingId
            where cu_Account.LeagueId = 1  and cu_account.state>0 and cu_account.state<5 ";
            //  pg.Sql = "select * from cu_Account where LeagueId = 1";
            ColumnInfo cl;
            cl = new ColumnInfo(); cl.FieldName = "AccountType"; cl.HeadText = "主帐目"; cl.Visible = true; cl.IsCondition = true; cl.ConditionPosition = 1; cl.DictTypeID = "D18"; cl.Width = 80; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "FlowingType"; cl.HeadText = "流水类型"; cl.Visible = false; cl.IsCondition = true; cl.ConditionPosition = 1; cl.DictTypeID = "D15"; cl.Width = 80; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "AccountMode"; cl.HeadText = "资金来源"; cl.Visible = false; cl.IsCondition = true; cl.ConditionPosition = 1; cl.DictTypeID = "D16"; cl.Width = 80; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "FlowingTypeName"; cl.HeadText = "流水类型"; cl.Visible = true; cl.Width = 80; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "AccountModename"; cl.HeadText = "资金来源"; cl.Visible = true; cl.Width = 80; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "Adate"; cl.DataType = Tag.DateTime; cl.HeadText = "日期"; cl.Visible = true; cl.DisplayFormat = "{0:dd / MM / yyyy}"; cl.IsCondition = true; cl.ConditionPosition = 1; cl.Width = 100; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "Account"; cl.HeadText = "金额"; cl.Visible = true; cl.IsSum = true; cl.Width = 80; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "CustMessage"; cl.HeadText = "客户信息"; cl.Visible = true; cl.Width = 300; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "Remark"; cl.HeadText = "摘要"; cl.Visible = true; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "createMessage"; cl.HeadText = "录入"; cl.Visible = true; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "AuditMessage"; cl.HeadText = "审核"; cl.Visible = true; pg.AddColumn(cl);
            cl = new ColumnInfo(); cl.FieldName = "stateName"; cl.HeadText = "状态"; cl.Visible = true; pg.AddColumn(cl);
         
            cl = new ColumnInfo(); cl.FieldName = "link"; cl.HeadText = "操作"; cl.IsSort = false; pg.AddColumn(cl);
            //cl = new ColumnInfo(); cl.FieldName = "state"; cl.HeadText = "状态"; cl.Visible = false; cl.IsCondition = true; pg.AddColumn(cl);
            return pg;
        }
    }
}